package com.xl.activiti.demo.config;

import com.xl.activiti.demo.listener.ActivitiGlobalEventListener;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 配置Activiti监听器
 * @author zhongwm
 */
@Slf4j
@Component
public class ActivitiConfig implements ProcessEngineConfigurationConfigurer {

    @Resource
    private ActivitiGlobalEventListener activitiGlobalEventListener;

    @Override
    public void configure(SpringProcessEngineConfiguration processEngineConfiguration) {
        List<ActivitiEventListener> activitiEventListeners = new ArrayList<>();
        activitiEventListeners.add(activitiGlobalEventListener);
        log.info("Register ActivitiGlobalEventListener.");
        processEngineConfiguration.setEventListeners(activitiEventListeners);
    }
}
